package com.demo;

//银行类
public class Account {
    private String name;
    private int balance;

    public Account(String name,int balance){
        this.name=name;
        this.balance=balance;

    }

    /**
     * @description:取
     * @author: JKchen
     * @date: 2022/10/30 18:45
     * @param: [i]
     * @return: void
     **/
    public void qu(int i) {
        setBalance(balance-i);
    }

    /**
     * @description:存
     * @author: JKchen
     * @date: 2022/10/30 18:45
     * @param: [i]
     * @return: void
     **/
    public void cun(int i) {

        setBalance(i+balance);
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

    //重写toString方法
    public String toString(){
        return "名字："+name+"\n账户余额："+balance;
    }


    //重写equals方法
    public boolean equals(Object obj){
        if(obj instanceof Account){
            return this.name==((Account)obj).name&&this.balance==((Account)obj).balance;
        }else{
            return false;
        }

    }


}
